package com.twang.stock.service.jinyan;

import com.twang.stock.entity.BaseCommon;
import com.twang.stock.entity.CompanyCodeInfo;
import com.twang.stock.entity.HotTag;
import com.twang.stock.entity.StockTag;
import com.twang.stock.mapper.BaseCommonMapper;
import com.twang.stock.mapper.CompanyCodeInfoMapper;
import com.twang.stock.mapper.HotTagMapper;
import com.twang.stock.mapper.StockTagMapper;
import com.twang.stock.common.HotTagCommon;
import org.assertj.core.util.Lists;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CommonService {
    public static String HOT_STOCK_KEY="hot_stock_key";
    //AI 芯片服务器
    public static String AI_COMPUTING_SERVER="ai_computing_server";

    //AI CPO
    public static String AI_CPO="ai_cpo";

    //AI 数据要素
    public static String AI_DATA="ai_data";

    //BK 1
    public static String BK_1="BK_1";

    //BK_2
    public static String BK_2="BK_2";

    //BK_3
    public static String BK_3="BK_3";

    //BK_4
    public static String BK_4="BK_4";

    //BK_5
    public static String BK_5="BK_5";

    //BK_6
    public static String BK_6="BK_6";


    public static String DX_QX_GD="DX_QX_GD";//短线情绪高度



    @Resource
    private BaseCommonMapper baseCommonMapper;

    @Resource
    private HotTagMapper hotTagMapper;

    @Resource
    private StockTagMapper stockTagMapper;

    @Resource
    private CompanyCodeInfoMapper companyCodeInfoMapper;

    public List<String> queryStockList() {
        List<String> stockList = Lists.newArrayList();
        Example example = new Example(CompanyCodeInfo.class);
        example.createCriteria().andEqualTo("type", 1);
        List<CompanyCodeInfo> companyCodeInfoList = companyCodeInfoMapper.selectByExample(example);
        stockList = companyCodeInfoList.stream().map(CompanyCodeInfo::getCompanyCode).collect(Collectors.toList());
        return stockList;
    }

    public List<String> getbankuiStock(List<String> stockList) {
        //查询监控的数据
        HotTag hotTag = new HotTag();
        hotTag.setHotTag(HotTagCommon.getYesterdayHotTag());
        HotTag tag = hotTagMapper.selectLastTagBYTask().get(0);
        //
        StockTag stockTag = new StockTag();
        stockTag.setTagId(tag.getId());
        List<StockTag> stockTagList = stockTagMapper.select(stockTag);
        List<Integer> companyIds = Lists.newArrayList();
        stockTagList.forEach(item -> {
            companyIds.add(item.getStockId());
        });
        Example example = new Example(CompanyCodeInfo.class);
        example.createCriteria().andIn("id", companyIds);
        List<CompanyCodeInfo> companyCodeInfoList = companyCodeInfoMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(companyCodeInfoList)) {
            for (CompanyCodeInfo info : companyCodeInfoList) {
                stockList.add(info.getCompanyCode());
            }
        }
        return stockList;
    }

    /**
     * 根据key 获取value
     *
     * @param key
     * @return
     */
    public BaseCommon getBaseCommon(String key) {
        BaseCommon param = new BaseCommon();
        param.setCommonKey(key);
        BaseCommon result = baseCommonMapper.selectOne(param);
        if (null != result) {
            return result;
        }
        return null;
    }

    /**
     * 根据key 获取value
     *
     * @param key
     * @return
     */
    public String getValue(String key) {
        BaseCommon param = new BaseCommon();
        param.setCommonKey(key);
        BaseCommon result = baseCommonMapper.selectOne(param);
        if (null != result) {
            return result.getCommonValue();
        }
        return null;
    }

    public static class UtilsKey{

        /**
         * 无效日期
         */
        public static String date_无效日期="date";

        /**
         * 无效时分
         */
        public static String minutes_无效时分="minutes";
    }
}
